package com.tt.controller;

import com.tt.pojo.Student;
import com.tt.service.StudentService;
import com.tt.vo.PageResult;
import com.tt.vo.SySResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService service;
    @GetMapping("/list")
    public SySResult getStudentList(PageResult pageResult){
        pageResult = service.getStudentList(pageResult);
        return SySResult.success(pageResult);
    }
    @GetMapping("listAll")
    public List<Student> getStudentAll(String name){
        return service.getStudentAll(name);
    }
   @PostMapping("/addStudent")
    public SySResult addStudent(Student student){
        service.addStudent(student);
        return SySResult.success();
   }
   @DeleteMapping("deleteStudent/{id}")
    public SySResult deleteStudent(@PathVariable Long id){
        service.deleteStudent(id);
        return SySResult.success();
    }
    @PutMapping("updateStudentById")
    public SySResult updateStudentById(Student student){
        service.updateStudentById(student);
        return SySResult.success();
    }
}
